﻿using Newtonsoft.Json.Linq;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Butcher.winform.EnterpriseForms.MessSalguhterPut
{
    public partial class SelectionOfBatch : Form
    {
        public SelectionOfBatch()
        {
            InitializeComponent();
            SLaughterHtml();
        }

        public int k;
        private DataGridViewCheckBoxColumn 选择;
        private DataGridViewTextBoxColumn 序号;
        private DataGridViewTextBoxColumn 供货商;
        private DataGridViewTextBoxColumn 进场日期;
        private DataGridViewTextBoxColumn 进场批次;
        private DataGridViewTextBoxColumn 代宰圈号;
        private DataGridViewTextBoxColumn 可用头数;
        private DataGridViewTextBoxColumn 均重;
        private DataGridViewTextBoxColumn 商品代号;
        private DataGridViewTextBoxColumn 静养时间;
        private DataGridViewTextBoxColumn 备注;
        public object[] kl;

        private void InitializeComponent()
        {
            label1 = new Label();
            comboBox1 = new ComboBox();
            label2 = new Label();
            dateTimePicker1 = new DateTimePicker();
            label3 = new Label();
            textBox1 = new TextBox();
            dataGridView1 = new DataGridView();
            选择 = new DataGridViewCheckBoxColumn();
            序号 = new DataGridViewTextBoxColumn();
            供货商 = new DataGridViewTextBoxColumn();
            进场日期 = new DataGridViewTextBoxColumn();
            进场批次 = new DataGridViewTextBoxColumn();
            代宰圈号 = new DataGridViewTextBoxColumn();
            可用头数 = new DataGridViewTextBoxColumn();
            均重 = new DataGridViewTextBoxColumn();
            商品代号 = new DataGridViewTextBoxColumn();
            静养时间 = new DataGridViewTextBoxColumn();
            备注 = new DataGridViewTextBoxColumn();
            ((ISupportInitialize)dataGridView1).BeginInit();
            SuspendLayout();
            // 
            // label1
            // 
            label1.AutoSize = true;
            label1.Location = new Point(164, 89);
            label1.Name = "label1";
            label1.Size = new Size(54, 20);
            label1.TabIndex = 0;
            label1.Text = "供货商";
            // 
            // comboBox1
            // 
            comboBox1.FormattingEnabled = true;
            comboBox1.Location = new Point(259, 81);
            comboBox1.Name = "comboBox1";
            comboBox1.Size = new Size(182, 28);
            comboBox1.TabIndex = 1;
            // 
            // label2
            // 
            label2.AutoSize = true;
            label2.Location = new Point(525, 84);
            label2.Name = "label2";
            label2.Size = new Size(69, 20);
            label2.TabIndex = 2;
            label2.Text = "进场日期";
            // 
            // dateTimePicker1
            // 
            dateTimePicker1.Location = new Point(649, 79);
            dateTimePicker1.Name = "dateTimePicker1";
            dateTimePicker1.Size = new Size(189, 27);
            dateTimePicker1.TabIndex = 3;
            // 
            // label3
            // 
            label3.AutoSize = true;
            label3.Location = new Point(938, 81);
            label3.Name = "label3";
            label3.Size = new Size(69, 20);
            label3.TabIndex = 4;
            label3.Text = "进场批次";
            // 
            // textBox1
            // 
            textBox1.Location = new Point(1076, 75);
            textBox1.Name = "textBox1";
            textBox1.Size = new Size(150, 27);
            textBox1.TabIndex = 5;
            // 
            // dataGridView1
            // 
            dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            dataGridView1.Columns.AddRange(new DataGridViewColumn[] { 选择, 序号, 供货商, 进场日期, 进场批次, 代宰圈号, 可用头数, 均重, 商品代号, 静养时间, 备注 });
            dataGridView1.Location = new Point(12, 226);
            dataGridView1.Name = "dataGridView1";
            dataGridView1.RowHeadersWidth = 62;
            dataGridView1.RowTemplate.Height = 32;
            dataGridView1.Size = new Size(1669, 472);
            dataGridView1.TabIndex = 6;
            dataGridView1.CellContentClick += dataGridView1_CellContentClick;
            // 
            // 选择
            // 
            选择.HeaderText = "选择";
            选择.MinimumWidth = 8;
            选择.Name = "选择";
            选择.Width = 150;
            // 
            // 序号
            // 
            序号.DataPropertyName = "liveAnimalweighingId";
            序号.HeaderText = "序号";
            序号.MinimumWidth = 8;
            序号.Name = "序号";
            序号.Width = 150;
            // 
            // 供货商
            // 
            供货商.DataPropertyName = "Suppliers";
            供货商.HeaderText = "供货商";
            供货商.MinimumWidth = 8;
            供货商.Name = "供货商";
            供货商.Width = 150;
            // 
            // 进场日期
            // 
            进场日期.DataPropertyName = "ApproachTime";
            进场日期.HeaderText = "进场日期";
            进场日期.MinimumWidth = 8;
            进场日期.Name = "进场日期";
            进场日期.Width = 150;
            // 
            // 进场批次
            // 
            进场批次.DataPropertyName = "ApproachBatch";
            进场批次.HeaderText = "进场批次";
            进场批次.MinimumWidth = 8;
            进场批次.Name = "进场批次";
            进场批次.Width = 150;
            // 
            // 代宰圈号
            // 
            代宰圈号.DataPropertyName = "SlaughterCircleName";
            代宰圈号.HeaderText = "代宰圈号";
            代宰圈号.MinimumWidth = 8;
            代宰圈号.Name = "代宰圈号";
            代宰圈号.Width = 150;
            // 
            // 可用头数
            // 
            可用头数.DataPropertyName = "Num";
            可用头数.HeaderText = "可用头数";
            可用头数.MinimumWidth = 8;
            可用头数.Name = "可用头数";
            可用头数.Width = 150;
            // 
            // 均重
            // 
            均重.DataPropertyName = "AverageWeight";
            均重.HeaderText = "均重";
            均重.MinimumWidth = 8;
            均重.Name = "均重";
            均重.Width = 150;
            // 
            // 商品代号
            // 
            商品代号.DataPropertyName = "ShoppingDesignationid";
            商品代号.HeaderText = "商品代号";
            商品代号.MinimumWidth = 8;
            商品代号.Name = "商品代号";
            商品代号.Width = 150;
            // 
            // 静养时间
            // 
            静养时间.DataPropertyName = "Time";
            静养时间.HeaderText = "静养时间";
            静养时间.MinimumWidth = 8;
            静养时间.Name = "静养时间";
            静养时间.Width = 150;
            // 
            // 备注
            // 
            备注.DataPropertyName = "Raemk";
            备注.HeaderText = "备注";
            备注.MinimumWidth = 8;
            备注.Name = "备注";
            备注.Width = 150;
            // 
            // SelectionOfBatch
            // 
            ClientSize = new Size(1701, 971);
            Controls.Add(dataGridView1);
            Controls.Add(textBox1);
            Controls.Add(label3);
            Controls.Add(dateTimePicker1);
            Controls.Add(label2);
            Controls.Add(comboBox1);
            Controls.Add(label1);
            Name = "SelectionOfBatch";
            Text = "选择";
            ((ISupportInitialize)dataGridView1).EndInit();
            ResumeLayout(false);
            PerformLayout();
        }

        private Label label1;
        private ComboBox comboBox1;
        private Label label2;
        private DateTimePicker dateTimePicker1;
        private TextBox textBox1;
        private DataGridView dataGridView1;
        private Label label3;

       List<int>GETLISt=new List<int>();
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
            k = Convert.ToInt32(row.Cells["序号"].Value);

            var c = 0;
            if(GETLISt!=null)
            {
                for (int i = 0; i < GETLISt.Count; i++)
                {

                    if (GETLISt[i] == k)
                    {
                        GETLISt.Remove(i+1);
                        c++;
                    }
                }
            }

            if(c==0)
            {
                GETLISt.Add(k);
            }            
        }


        


        public void SLaughterHtml()
        {
            var url = @"http://localhost:5229/api/Batch/SlaughterSelectionList";
            NEWGET list = new NEWGET();
            list.approachTime =null;
            list.suppliers = comboBox1.Text;
            list.approachBatch = textBox1.Text;
            HttpClient client = new HttpClient();
            var context = new StringContent(JsonSerializer.Serialize<NEWGET>(list), Encoding.UTF8);
            context.Headers.Remove("Content-Type");
            context.Headers.Add("Content-Type", "application/json");
            string result=client.PostAsync(url, context).Result.Content.ReadAsStringAsync().Result;
            JObject jsonresult=JObject.Parse(result);

            var results = jsonresult["date"].Value<JArray>();

            dataGridView1.DataSource = results;

        }


        public class NEWGET
        {

            public string approachTime { get; set; }
            public string suppliers { get; set; }

            public string approachBatch { get; set; }


        }


    }
}
